package com.vhall.component.service.account;

import com.vhall.component.entity.room.enums.LiveContentTypeEnum;
import com.vhall.component.entity.room.vo.LiveWatchCheckRequestVO;
import com.vhall.component.entity.room.vo.LiveWatchCheckResponseVO;
import com.vhall.component.framework.common.exception.BusinessException;
import com.vhall.component.plugin.common.exception.BizErrorCode;
import com.vhall.component.service.account.impl.InvestmentAdvisoryLiveWatchCheck;
import com.vhall.component.service.account.impl.InvestmentEducationLiveWatchCheck;
import com.vhall.component.service.account.impl.ProductLiveWatchCheck;
import com.vhall.component.service.account.impl.SecuritiesResearchLiveWatchCheck;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

/**
 * 直播观看检查执行类
 *
 * @author xing.wang
 * @date 2023/8/19
 */
@Component
@RequiredArgsConstructor
public class LiveWatchCheckHandle {
    private Map<Integer, LiveWatchCheck> liveWatchCheckMap = new HashMap<>();
    @Resource
    private  InvestmentEducationLiveWatchCheck investmentEducationLiveWatchCheck;
    @Resource
    private  InvestmentAdvisoryLiveWatchCheck investmentAdvisoryLiveWatchCheck;
    @Resource
    private  ProductLiveWatchCheck productLiveWatchCheck;
    @Resource
    private  SecuritiesResearchLiveWatchCheck securitiesResearchLiveWatchCheck;
    @PostConstruct
    public void init(){
//        投教类
        liveWatchCheckMap.put(LiveContentTypeEnum.TYPE_1.getValue(),investmentEducationLiveWatchCheck);
//        投顾类
        liveWatchCheckMap.put(LiveContentTypeEnum.TYPE_2.getValue(),investmentAdvisoryLiveWatchCheck);
//        产品类
        liveWatchCheckMap.put(LiveContentTypeEnum.TYPE_3.getValue(),productLiveWatchCheck);
//        证券研究类
        liveWatchCheckMap.put(LiveContentTypeEnum.TYPE_4.getValue(),securitiesResearchLiveWatchCheck);
    }

    /**
     * 进行观看直播检查
     * @param vo
     * @return
     */
    public LiveWatchCheckResponseVO liveWatchCheck(LiveWatchCheckRequestVO vo){
        LiveWatchCheck liveWatchCheck = Optional.ofNullable(liveWatchCheckMap.get(vo.getLiveContentType())).orElseThrow(()->new BusinessException(BizErrorCode.LIVE_CONTENT_TYPE_ERR));
        return liveWatchCheck.liveWatchCheck(vo);
    }
}
